<?php
namespace App\Admin\Controllers\Traits\WxSettingTraits;

use App\Lib\WeApp\WeApp;
use App\Wen\Utils\AdminUtils;
use App\Wen\Utils\FieldUtils;
use App\Wen\Utils\GatewayUtils;
use App\Wen\Utils\Settings;
use App\Wen\Utils\SiteUtils;
use App\Wen\Utils\Utils;
use Dcat\Admin\Form\NestedForm;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Form;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

trait formFrontTrait{

    protected $uniapp_down_url = '';
    protected $page_json_url = '';
    protected $uniscss_url = '';
    protected $manifest_json_url = '';

    public function index_front(Content $content)
    {
        $this->uniapp_down_url = admin_url('/front/uniapp');
        $this->page_json_url = admin_url('/front/pagejson');
        $this->uniscss_url = admin_url('/front/uniscss');
        $this->manifest_json_url = admin_url('/front/manifestjson');

        return $content->title('前端项目')
            ->description('每次更改配置，需要重新下载项目代码，才会生效')
//            ->body($this->buildPreviewButton())
//            ->body($this->newline())
            ->body(
                <<<HTML
<style>
.tools{display: flex;}
.front-button{display: inline-flex;background-color:#000;color:#ffffff;padding:0.5rem 1.4rem;font-size:0.875rem;line-height:1.25rem;font-weight:700;text-align:center;vertical-align:middle;align-items:center;border-radius:0.5rem;gap:0.75rem;border:none;cursor:pointer;box-shadow:0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06);transition:.6s ease;margin-right: 20px;}.front-button .fa{font-size: 23px;}.front-button:hover{box-shadow:none;color: #ffffff;}
.file-down-button{
    display: inline-flex;
    background-color: #ffffff !important;
    color: #2c3e50!important;
    padding: 0.5rem 1.4rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
    align-items: center;
    border-radius: 0.5rem;
    gap: 0.75rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    transition: .6s ease;
}
</style>
<div class="tools" style="margin-bottom: 15px;">
    <a class="front-button" href="{$this->uniapp_down_url}" target="_blank">
      <i class="fa fa-folder"></i>
      UniApp 项目代码
    </a>
    <form id="miniCodeModel" action="$this->page_json_url" method="post" style="margin-right: 20px;margin-bottom: 20px;">
        <input name="type" value="front_page_json_url" hidden>
        <a class="file-down-button" onclick="mini_model_code('$this->page_json_url', 'miniCodeModel')" target="_blank">
      pages.json文件
    </a>
    </form>
    <form id="miniCodeModel2" action="$this->uniscss_url" method="post" style="margin-right: 20px;margin-bottom: 20px;">
        <input name="type" value="front_page_json_url" hidden>
        <a class="file-down-button" onclick="mini_model_code('$this->uniscss_url', 'miniCodeModel2')" target="_blank">
      uni.scss文件
    </a>
    </form>
    <form id="miniCodeModel3" action="$this->manifest_json_url" method="post" style="margin-right: 20px;margin-bottom: 20px;">
        <input name="type" value="front_page_json_url" hidden>
        <a class="file-down-button" onclick="mini_model_code('$this->manifest_json_url', 'miniCodeModel3')" target="_blank">
      manifest.json文件
    </a>
    </form>
</div>

<div class="card">{$this->form_front()->render()}</div>
<script>
$('#code-string-modal-btn').click(function () {
            $.get('$this->page_json_url', function (data) {
                console.log(data);
                var modalBody = $('<pre>').text(data);
                Admin.modal.open({
                    title: '代码字符串',
                    width: '60%',
                    content: modalBody,
                    // 其他模态框配置属性
                });
            });
        });
</script>
HTML

            );
    }


    protected function form_front(){
        $form = new Form();
        $form->confirm('您确定要提交表单吗？', 'content');
        $form->disableResetButton();


        $form->tab('自定义css', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">tips：配置项会直接注入对应的文件，app.scss文件需要尽量保持精简，mini的前端css几乎都页面独立</div>';
            }, '');
            $form->htmlEditor('app_custom_css_app_scss', 'app.scss')->help('文件路径：/app.scss 全局css文件')->default(Settings::get('app_custom_css_app_scss', ''));
            $form->htmlEditor('app_custom_css_circle_scss', 'circle_scss')->help('文件路径：/pages/template/circle.scss 笔记相关的css文件')->default(Settings::get('app_custom_css_app_scss', ''));
            $form->html(function () {
                return '<div><a style="color: blue;font-weight: bold;" href="'.admin_url('settings2/diycode').'" target="_blank">更多自定义></a></div>';
            }, '');
        });

        $form->tab('tarbar', function (Form $form) {
            $form->html(function () {
                return '<div style="color: #414750;padding: 10px;border-radius: 5px;display: flex;max-width: 100%; display: flex;flex-wrap: wrap;">
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/1.png" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/1.png?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">1：首页</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/2.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/2.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">2：商城</div>
</div>

<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/3.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/3.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">3：发布</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/4.png" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/4.png?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">4：消息</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/5.png" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/5.png?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">5：我</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/19.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/19.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">19：'.env('circle_call', '圈子').'发现</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/50001.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/50001.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">50001：领养</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/50.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/50.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">50：'.env('circle_call', '圈子').'广场</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/87.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/87.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">87：商品分类</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/971.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/971.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">97：发布2</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/100.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/100.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">100：二手</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/131.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/131.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">131：课程表</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/139.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/139.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">139：商品发现</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/142.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/142.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">142：图标发现</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/130.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/130.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">130：选票</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/157.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/157.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">157：组局</div>
</div>
<div style="margin-right: 20px;margin-bottom: 20px;">
    <a href="https://img.mini.minisns.cn/images/mini/uni/165.jpg" target="_blank"><img src="https://img.mini.minisns.cn/images/mini/uni/165.jpg?imageMogr2/thumbnail/94x/format/webp/interlace/1"></a>
    <div style="text-align: center;font-weight: bold;margin-top: 10px;">165：城市首页</div>
</div>
</div>';
            }, '');

            $form->text('uni_tabbar_list', 'tabbar配置')->help('填序号，英文逗号隔开，3要么没有，要么在中间')->default(Settings::get('uni_tabbar_list', '1,19,3,4,5'));
            $form->image('uni_tabbar_style_publish_img', 'App发布按钮')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/hbx/custom-tabbar/fabu.png" target="_blank">点击下载默认图</a>，小程序不用设置，你若想和官方保持一致，但是颜色需要换一下，可以群里艾特我，我可以给你不同颜色的发布按钮')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_publish_img', 'https://img.mini.minisns.cn/hbx/custom-tabbar/fabu.png'));
            $form->radio('uni_tabbar_style', 'tabbar样式')->options([1=>'官方小红书', 2 => '微博式' ])->help('<a href="https://img.mini.minisns.cn/images/page/default_xiaoguo.jpg" target="_blank">微博式效果</a>')->default(Settings::get('uni_tabbar_style', 1))->when(1, function (Form $form){

            })->when(2, function (Form $form){
                $form->row(function ($form) {
                    $form->width(2)->text('uni_tabbar_style_1_text', '第一个')->default(Settings::get('uni_tabbar_style_1_text', '首页'));
                    $form->width(2)->text('uni_tabbar_style_2_text', '第二个')->default(Settings::get('uni_tabbar_style_2_text', '发现'));
                    $form->width(2)->text('uni_tabbar_style_3_text', '第三个')->default(Settings::get('uni_tabbar_style_3_text', ''));
                    $form->width(2)->text('uni_tabbar_style_4_text', '第四个')->default(Settings::get('uni_tabbar_style_4_text', '消息'));
                    $form->width(2)->text('uni_tabbar_style_5_text', '第五个')->default(Settings::get('uni_tabbar_style_5_text', '我的'));
                });
                $form->row(function ($form) {
                    $form->width(2)->image('uni_tabbar_style_1_icon_1', '选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/1.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_1_icon_1', 'https://img.mini.minisns.cn/images/tabbar/1.png'));
                    $form->width(2)->image('uni_tabbar_style_2_icon_1', '选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/2.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_2_icon_1', 'https://img.mini.minisns.cn/images/tabbar/2.png'));
                    $form->width(2)->image('uni_tabbar_style_3_icon_1', '选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/3.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_3_icon_1', 'https://img.mini.minisns.cn/images/tabbar/3.png'));
                    $form->width(2)->image('uni_tabbar_style_4_icon_1', '选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/4.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_4_icon_1', 'https://img.mini.minisns.cn/images/tabbar/4.png'));
                    $form->width(2)->image('uni_tabbar_style_5_icon_1', '选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/5.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_5_icon_1', 'https://img.mini.minisns.cn/images/tabbar/5.png'));
                });
                $form->row(function ($form) {
                    $form->width(2)->image('uni_tabbar_style_1_icon_2', '未选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/11.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_1_icon_2', 'https://img.mini.minisns.cn/images/tabbar/11.png'));
                    $form->width(2)->image('uni_tabbar_style_2_icon_2', '未选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/22.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_2_icon_2', 'https://img.mini.minisns.cn/images/tabbar/22.png'));
                    $form->width(2)->image('uni_tabbar_style_3_icon_2', '未选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/33.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_3_icon_2', 'https://img.mini.minisns.cn/images/tabbar/33.png'));
                    $form->width(2)->image('uni_tabbar_style_4_icon_2', '未选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/44.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_4_icon_2', 'https://img.mini.minisns.cn/images/tabbar/44.png'));
                    $form->width(2)->image('uni_tabbar_style_5_icon_2', '未选中')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/images/tabbar/55.png" target="_blank">点击下载默认图</a>，64*64 png格式')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_style_5_icon_2', 'https://img.mini.minisns.cn/images/tabbar/55.png'));
                });
            });
        });

        $form->tab('manifest.json', function (Form $form) {
            $form->text('uni_appid', 'uni-app应用标识（AppID）')->placeholder('__UNI__FDF10EB')->help('如果是第一次下载minisns前端，还没有这个AppId，就先随便填个，然后去hbuilderx生成')->default(Settings::get('uni_appid', ''));
            $form->text('uni_name', '应用名称')->placeholder('宠也')->default(Settings::get('uni_name', ''));
            $form->text('uni_description', '应用描述')->placeholder('Hello，宠也')->default(Settings::get('uni_description', ''));
            $form->text('app_qq_app_appid', 'QQ移动应用appid')->help('用于分享')->placeholder('101851902')->default(Settings::get('app_qq_app_appid', ''));
            $form->text('app_weibo_app_appid', '微博移动应用appid')->help('用于分享')->placeholder('860301646')->default(Settings::get('app_weibo_app_appid', ''));

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">定位</div>';
            }, '');
            $form->text('app_gaode_appkey_ios', 'ios平台高德定位地图应用KEY')->placeholder('270c889d2c44944f88d3400959d0d1dd')->default(Settings::get('app_gaode_appkey_ios', ''));
            $form->text('app_gaode_appkey_android', 'Android平台高德定位地图应用KEY')->placeholder('6762fef37b1eb3128c09d3ed4dc1b1c2')->default(Settings::get('app_gaode_appkey_android', ''));

        });

        $form->tab('uni.scss', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">颜色</div>';
            }, '');
            $form->color('uni_color_primary', '主题色')->help('默认值：#fc3a72')->default(Settings::get('uni_color_primary', '#fc3a72'));
            $form->color('uni_color_primary_lightest', '浅浅主题色')->help('默认值：#fee2ea')->default(Settings::get('uni_color_primary_lightest', '#fee2ea'));
            $form->divider();
            $form->color('uni_scss_used_mall', '二手闲置系统主题色')->help('默认值：#fbe74f')->default(Settings::get('uni_scss_used_mall', '#fbe74f'));
            $form->divider();
            $form->color('uni_scss_color_follow', '按钮背景颜色')->help('默认值：#fc3a73')->default(Settings::get('uni_scss_color_follow', '#fc3a73'));
            $form->color('uni_scss_color_follow_font', '按钮字体颜色')->help('默认值：#ffffff')->default(Settings::get('uni_scss_color_follow_font', '#ffffff'));
            $form->divider();
            $form->color('uni_scss_color_love', '爱心')->help('默认值：#fc3a73')->default(Settings::get('uni_scss_color_love', '#fc3a73'));
            $form->color('uni_scss_color_collected', '收藏')->help('默认值：#f2bf66')->default(Settings::get('uni_scss_color_collected', '#f2bf66'));
            $form->color('uni_color_authentication', '认证')->help('默认值：#199bec')->default(Settings::get('uni_color_authentication', '#199bec'));
            $form->color('uni_color_official', '官方')->help('默认值：#000000')->default(Settings::get('uni_color_official', '#000000'));
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">等级颜色</div>';
            }, '');
            $form->color('uni_lv1_color', 'lv1')->help('默认值：#c6c4c5')->default(Settings::get('uni_lv1_color', '#c6c4c5'));
            $form->color('uni_lv2_color', 'lv2')->help('默认值：#91d660')->default(Settings::get('uni_lv2_color', '#91d660'));
            $form->color('uni_lv3_color', 'lv3')->help('默认值：#7bcdef')->default(Settings::get('uni_lv3_color', '#7bcdef'));
            $form->color('uni_lv4_color', 'lv4')->help('默认值：#febb8b')->default(Settings::get('uni_lv4_color', '#febb8b'));
            $form->color('uni_lv5_color', 'lv5')->help('默认值：#ee672a')->default(Settings::get('uni_lv5_color', '#ee672a'));
            $form->color('uni_lv6_color', 'lv6')->help('默认值：#ff0000')->default(Settings::get('uni_lv6_color', '#ff0000'));
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">文字尺寸</div>';
            }, '');
            $form->decimal('uni_font_size_sm', '小号')->help('单位：rpx， 默认值：24')->default(Settings::get('uni_font_size_sm', 24));
            $form->decimal('uni_font_size_base', '中号')->help('评论内容等。 单位：rpx 默认值：28')->default(Settings::get('uni_font_size_base', 28));
            $form->decimal('uni_font_size_medium', '中大号')->help('笔记内容等。 单位：rpx 默认值：30')->default(Settings::get('uni_font_size_medium', 30));
            $form->decimal('uni_font_size_lg', '大号')->help('单位：rpx，默认值：32')->default(Settings::get('uni_font_size_lg', 32));
            $form->decimal('uni_font_size_lg_er', '更大号')->help('单位：rpx，默认值：34')->default(Settings::get('uni_font_size_lg_er', 34));
        });

        $form->tab('DIY-全局', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">开关</div>';
            }, '');
            $form->html(function () {
                return '<div><img src="https://img.mini.minisns.cn/images/loading_tip.gif" style="width: 100px;"></div>';
            }, '');
            $form->radio('uni_scss_loading_style', '全局加载中样式')->options([0=>'小红书式', 1=>'抖音式'])->help('示例上面是抖音，下面是小红书')->default(Settings::get('uni_scss_loading_style', 0));
            $form->radio('uni_scss_global_hall_ball', '管理员悬浮球')->options([0=>'不显示', 1=>'显示'])->help('就是右下角那个可以滑动的悬浮球')->default(Settings::get('uni_scss_global_hall_ball', 1));

        });

        $form->tab('DIY-首页', function (Form $form) {

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">首页-公告</div>';
            }, '');
            $form->number('page_index_notice_box_height', '公告-高度(rpx)')->help('默认值：65')->default(Settings::get('page_index_notice_box_height', 65));
            $form->number('page_index_notice_font_size', '公告-字体大小(rpx)')->help('默认值：25')->default(Settings::get('page_index_notice_font_size', 25));
            $form->number('page_index_notice_img_height', '公告-图标高度(rpx)')->help('默认值：30')->default(Settings::get('page_index_notice_img_height', 30));

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">首页-金刚区</div>';
            }, '');
            $form->number('page_index_box_menu_width', '金刚区-图片宽度(rpx)')->help('默认值：30')->default(Settings::get('page_index_box_menu_width', 70));
            $form->number('page_index_box_menu_wrap_width', '金刚区-单个菜单宽度(rpx)')->help('默认值：100  先调整上面的的图片大小，大小确认以后，再调整这里使整体看起来居中')->default(Settings::get('page_index_box_menu_wrap_width', 100));
            $form->number('page_index_box_menu_font_size', '金刚区-文字大小(rpx)')->help('默认值：26')->default(Settings::get('page_index_box_menu_font_size', 26));
            $form->rate('page_index_box_menu_border_radius', '金刚区-圆角(rpx)')->help('默认值：50')->default(Settings::get('page_index_box_menu_border_radius', 50));


            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">首页-热门-热门话题</div>';
            }, '');
            $form->number('page_index_topics_top_height', '热门话题-总高度(rpx)')->help('默认值：400  总高度可以调节多少行')->default(Settings::get('page_index_topics_top_height', 400));
            $form->number('page_index_topics_top_width', '热门话题-宽度(rpx)')->help('默认值：400')->default(Settings::get('page_index_topics_top_height', 400));
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">首页-右下角-刷新悬浮按钮</div>';
            }, '');

            $form->radio('page_refresh_fixed_button', '悬浮刷新按钮')->options([0=>'不显示', 1=>'显示'])->help('<a href="https://img.mini.minisns.cn/images/page/refresh_tip.jpg" target="_blank">点击查看效果</a>，'.env('circle_call', '圈子').'页也有，同时起作用')->default(Settings::get('page_refresh_fixed_button', 0));
            $form->radio('page_publish_fixed_button', '悬浮发笔记按钮')->options([0=>'不显示', 1=>'显示'])->help('<a href="https://img.mini.minisns.cn/images/page/publish_icon_tip.jpg" target="_blank">点击查看效果</a>')->default(Settings::get('page_publish_fixed_button', 0));

        });

        $form->tab('DIY-瀑布流', function (Form $form) {
            $form->rate('waterfall_img_max_height', '瀑布流-图片最大高度（rpx）')->help('默认值：600')->default(Settings::get('waterfall_img_max_height', 600));
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">随机背景</div>';
            }, '');
            $form->number('waterfall_random_bg_font_size', '随机背景-文字大小(rpx)')->help('默认值：30')->default(Settings::get('waterfall_random_bg_font_size', 30));
            $form->number('waterfall_random_bg_padding', '随机背景-内间距(rpx)')->help('默认值：20')->default(Settings::get('waterfall_random_bg_padding', 20));
            $form->number('waterfall_random_bg_max_height', '随机背景-文字行数(rpx)')->help('默认值：120，大概40rpx一行')->default(Settings::get('waterfall_random_bg_max_height', 120));
            $form->radio('waterfall_random_bg_justify_content', '随机背景-文字位置(rpx)')->options(['start'=>'上边', 'center'=>'居中'])->help('默认值：上边')->default(Settings::get('waterfall_random_bg_justify_content', 'start'));
        });

        $form->tab('DIY-列表式', function (Form $form) {
            $form->radio('post_list_sex_display', '显示性别')->options([0=>'显示', 1=>'不显示'])->default(Settings::get('post_list_sex_display', 0));
            $form->number('ellipsis_content_height', '内容折叠-高度(rpx)')->help('默认值：150')->default(Settings::get('ellipsis_content_height', 150));
            $form->radio('post_list_footer_share_icon', '分享图标')->options(['e67e'=>'<i class="mini-icon mini-fenxiang2"></i>', 'e60d'=>'<i class="mini-icon mini-fenxiang5"></i>', 'e68d'=>'<i class="mini-icon mini-fasong"></i>', 'e61e'=>'<i class="mini-icon mini-fenxiang"></i>'])->default(trim(Settings::get('post_list_footer_share_icon', 'e67e'), '\\'));
            $form->number('post_list_footer_icon_font_size', '底部图标(rpx)')->help('默认值：42')->default(Settings::get('post_list_footer_icon_font_size', 42));
        });

        $form->tab('DIY-评论', function (Form $form) {
            $form->radio('comment_list_sex_display', '显示性别')->options([0=>'显示', 1=>'不显示'])->default(Settings::get('comment_list_sex_display', 0));
            $form->text('comment_form_placeholder_text', '评论框提示')->help('默认值：此时此刻想说~')->default(Settings::get('comment_form_placeholder_text', '此时此刻想说~'));
        });

        $form->tab('DIY-详情页', function (Form $form) {
            $form->radio('sticky_clrcle_display', env('circle_call', '圈子').'展示')->options([0=>'默认', 1=>'小'])->default(Settings::get('sticky_clrcle_display', 0));
        });

        $form->tab('第三方PC端-DESAI', function (Form $form) {

            $form->html(function () {
                return '
<div class="tools" style="margin-bottom: 15px;">
    <a class="front-button" href="'.admin_url('/front/desai/pc').'" target="_blank" style="background-color: #8be1d7;color:#000000;">
      <i class="fa fa-folder"></i>
            DESAI PC端 下载
    </a>
</div>';
            }, '');
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">1、感谢DESAI公司的鼎力支持，才会有这个pc端的初始版本，消耗财力10w+，且用且珍惜，后面的更新由我负责，但优先级不高<br/>2、这里的配置每次更改，都需要重新下载，然后上传部署代码，用了cdn的需要清理缓存才能看到更改的效果</div>';
            }, '');
            $form->text('desai_pc_page_welcome', '欢迎语')->placeholder('欢迎来到迷你SNS演示社区-宠也')->default(Settings::get('desai_pc_page_welcome', '欢迎来到迷你SNS演示社区-宠也'));
            $form->text('desai_pc_page_title', '标题')->placeholder('MiNiSNS演示社区-宠也')->help('<a href="https://doc.minisns.cn/doc/136/" target="_blank">上线教程请看</a>')->default(Settings::get('desai_pc_page_title', 'MiNiSNS演示社区-宠也'));
            $form->textarea('desai_pc_page_keyword', '关键词')->placeholder(env('circle_call', '圈子').',会员,裂变,分销,知识付费,模糊搜索,商城,双货币,认证,论坛,瀑布流,同城校园,闲置,即时聊天,语音,acg,seo,手机号,建圈,公告,话题,评论,签到,任务,暗黑')->default(Settings::get('desai_pc_page_keyword', '圈子,会员,裂变,分销,知识付费,模糊搜索,商城,双货币,认证,论坛,瀑布流,同城校园,闲置,即时聊天,语音,acg,seo,手机号,建圈,公告,话题,评论,签到,任务,暗黑'));
            $form->textarea('desai_pc_page_desc', '描述')->placeholder('minisns666')->default(Settings::get('desai_pc_page_desc', 'minisns666'));
            $form->image('desai_pc_logo', 'logo')->url('files/uploads')->help('<a href="https://img.minisns.cn/desai/DESAI%402x.png" target="_blank">点击下载默认图</a>')->uniqueName()->autoUpload()->required()->default(Settings::get('desai_pc_logo', 'https://img.minisns.cn/desai/DESAI%402x.png'));
            $form->image('desai_pc_icon', 'icon')->url('files/uploads')->help('<a href="https://img.minisns.cn/desai/favicon.ico" target="_blank">点击下载默认图</a>')->uniqueName()->autoUpload()->required()->default(Settings::get('desai_pc_icon', 'https://img.minisns.cn/desai/favicon.ico'));
            $form->checkbox('desai_pc_right_bottom_qrcode', '右侧栏底部二维码')->options([1=>'小程序码', 2=>'公众号码', 3 => 'App二维码', 4=>'抖音二维码'])->help('仅且只能选两个，二维码请去 "全局配置->常规->二维码"')->default(Settings::get('desai_pc_right_bottom_qrcode', [1,2]));
            $form->radio('desai_pc_app_order_pay_provider', '支付平台')->help('更改需要重新下载部署')->options(['wxpay' => '微信支付', 'alipay'=>'支付宝'])->default(Settings::get('desai_pc_app_order_pay_provider', 'wxpay'));
            $form->radio('desai_pc_app_order_pay_type', '支付方式')->options(['code' => '官方扫码支付', 'yi'=>'易支付'])->default(Settings::get('desai_pc_app_order_pay_type', 'code'));
        });

        $form->tab('微信小程序-插件', function (Form $form) {

            $form->radio('mini_plugin_ant_movie_switch', '蚂蚁联盟-卖电影票')->options([0=>'关闭', 1=>'开启'])->help('开启之后，在微信开发者工具里，会提示你授权插件，<a href="https://img.mini.minisns.cn/images/antmovie-plugin-add.png" target="_blank">如图</a>')->when(1, function (Form $form){
                $tip = 'plugin://mayi-movie/index?movieapikey='.Settings::get('mini_plugin_ant_movie_apikey', '266f484800d4b881');
                $form->html(function () use ($tip){
                    return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">电影票路径：'.$tip.' <br/>（在任意可跳转路径的地方可配置该路径，则会跳转到电影票界面）</div>';
                }, '');
                $form->text('mini_plugin_ant_movie_apikey', 'apikey')->help('去<a href="http://s.91jdj.cn/ha3DA" target="_blank">蚂蚁星球</a>申请自己的<a href="https://img.mini.minisns.cn/images/apikey.jpg" target="_blank">apikey</a>, 填到这里，然后提交保存，刷新浏览器，上面的路径就替换成了你的apikey了，你再用这个路径作为入口，去其他地方配置')->default(Settings::get('mini_plugin_ant_movie_apikey', '266f484800d4b881'));
                if(!_empty_(Settings::get('mini_plugin_ant_movie_apikey', ''))){
                    $form->html(function () use ($tip){
                        return Cache::remember('ant:movie:share:url', 3600, function () use ($tip){
                            $new_app = new WeApp();
                            $wxlink = $new_app->getWxLink();
                            if($wxlink){
                                try {
                                    $url_link = $wxlink->genWxUrllink('/pages/tabbar/index/index', 'direct='. _encodeURIComponent('type=6&id='.$tip));
                                    return '移动推广链接：<span style="color: red;">'.$url_link.'</span>';
                                }catch (\Exception $e){
                                    return '';
                                }
                            }
                            return '';
                        });
                    }, '');
                }
            })->default(Settings::get('mini_plugin_ant_movie_switch', 0));
            $form->divider();

        });

        $form->tab('文字替换', function (Form $form) {
            $uni_front_replace_list = Settings::get('uni_front_replace_list', []);
            if(isset($uni_front_replace_list['keys'])){
                Settings::set('uni_front_replace_list', [], true);
                $uni_front_replace_list = [];
            }
            $form->keyValue('uni_front_replace_list', '文字替换')->setKeyLabel('文字')->setValueLabel('替换成')->default($uni_front_replace_list);
        });

        $form->action('settings/action/front');
        return $form;
    }


    public function front(Request $request){

        if(!file_exists(public_path('storage/tarbar'))){
            mkdir(public_path('storage/tarbar'), 0777);
        }
        if(!_empty_($request->input('uni_tabbar_style_publish_img')) && ( !file_exists(public_path('storage/tarbar/fabu.png')) || Settings::get('uni_tabbar_style_publish_img', '') != $request->input('uni_tabbar_style_publish_img')) ){
            $fabu = fopen(public_path('storage/tarbar/fabu.png'), 'w');
            $contents = file_get_contents($request->input('uni_tabbar_style_publish_img'));
            fwrite($fabu, $contents);
            fclose($fabu);
        }

        foreach ([1,2,3,4,5] as $index){
            if(!_empty_($request->input('uni_tabbar_style_'.$index.'_icon_1')) && (!file_exists(public_path('storage/tarbar/'.$index.'.png')) || Settings::get('uni_tabbar_style_'.$index.'_icon_1', '') != $request->input('uni_tabbar_style_'.$index.'_icon_1'))){
                $fabu = fopen(public_path('storage/tarbar/'.$index.'.png'), 'w');
                $contents = file_get_contents($request->input('uni_tabbar_style_'.$index.'_icon_1'));
                fwrite($fabu, $contents);
                fclose($fabu);
            }
            if(!_empty_($request->input('uni_tabbar_style_'.$index.'_icon_2')) && (!file_exists(public_path('storage/tarbar/'.$index.$index.'.png')) || Settings::get('uni_tabbar_style_'.$index.'_icon_2', '') != $request->input('uni_tabbar_style_'.$index.'_icon_2')) ){
                $fabu = fopen(public_path('storage/tarbar/'.$index.$index.'.png'), 'w');
                $contents = file_get_contents($request->input('uni_tabbar_style_'.$index.'_icon_2'));
                fwrite($fabu, $contents);
                fclose($fabu);
            }
        }

        SiteUtils::forget_config_data();

        Settings::set('uni_tabbar_list', trim($request->input('uni_tabbar_list'), ','), true);

        Settings::set('app_custom_css_app_scss', $request->input('app_custom_css_app_scss'), true);
        Settings::set('app_custom_css_circle_scss', $request->input('app_custom_css_circle_scss'), true);

        Settings::set('uni_appid', $request->input('uni_appid'), true);
        Settings::set('uni_name', $request->input('uni_name'), true);
        Settings::set('uni_description', $request->input('uni_description'), true);
        Settings::set('app_qq_app_appid', $request->input('app_qq_app_appid'), true);
        Settings::set('app_weibo_app_appid', $request->input('app_weibo_app_appid'), true);

        Settings::set('uni_scss_loading_style', $request->input('uni_scss_loading_style'), true);
        Settings::set('uni_scss_global_hall_ball', $request->input('uni_scss_global_hall_ball'), true);

        Settings::set('uni_scss_color_follow', $request->input('uni_scss_color_follow'), true);
        Settings::set('uni_scss_color_follow_font', $request->input('uni_scss_color_follow_font'), true);
        Settings::set('uni_scss_color_love', $request->input('uni_scss_color_love'), true);
        Settings::set('uni_scss_color_collected', $request->input('uni_scss_color_collected'), true);
        Settings::set('uni_scss_font_title_size', $request->input('uni_scss_font_title_size'), true);
        Settings::set('uni_scss_font_content_size', $request->input('uni_scss_font_content_size'), true);
        Settings::set('uni_scss_font_comment_size', $request->input('uni_scss_font_comment_size'), true);
        Settings::set('uni_scss_font_waterfall_size', $request->input('uni_scss_font_waterfall_size'), true);

        Settings::set('app_gaode_appkey_ios', $request->input('app_gaode_appkey_ios'), true);
        Settings::set('app_gaode_appkey_android', $request->input('app_gaode_appkey_android'), true);

        Settings::set('uni_color_primary', $request->input('uni_color_primary'), true);
        Settings::set('uni_color_primary_lightest', $request->input('uni_color_primary_lightest'), true);
        Settings::set('uni_scss_used_mall', $request->input('uni_scss_used_mall'), true);


        Settings::set('uni_color_authentication', $request->input('uni_color_authentication'), true);
        Settings::set('uni_color_official', $request->input('uni_color_official'), true);

        Settings::set('uni_lv1_color', $request->input('uni_lv1_color'), true);
        Settings::set('uni_lv2_color', $request->input('uni_lv2_color'), true);
        Settings::set('uni_lv3_color', $request->input('uni_lv3_color'), true);
        Settings::set('uni_lv4_color', $request->input('uni_lv4_color'), true);
        Settings::set('uni_lv5_color', $request->input('uni_lv5_color'), true);
        Settings::set('uni_lv6_color', $request->input('uni_lv6_color'), true);

        Settings::set('uni_font_size_sm', $request->input('uni_font_size_sm'), true);
        Settings::set('uni_font_size_base', $request->input('uni_font_size_base'), true);
        Settings::set('uni_font_size_medium', $request->input('uni_font_size_medium'), true);
        Settings::set('uni_font_size_lg', $request->input('uni_font_size_lg'), true);
        Settings::set('uni_font_size_lg_er', $request->input('uni_font_size_lg_er'), true);

        Settings::set('page_index_notice_box_height', $request->input('page_index_notice_box_height'), true);
        Settings::set('page_index_notice_font_size', $request->input('page_index_notice_font_size'), true);
        Settings::set('page_index_notice_img_height', $request->input('page_index_notice_img_height'), true);
        Settings::set('page_index_topics_top_height', $request->input('page_index_topics_top_height'), true);
        Settings::set('page_index_box_menu_width', $request->input('page_index_box_menu_width'), true);
        Settings::set('page_index_box_menu_wrap_width', $request->input('page_index_box_menu_wrap_width'), true);
        Settings::set('page_index_box_menu_font_size', $request->input('page_index_box_menu_font_size'), true);
        Settings::set('page_index_box_menu_border_radius', $request->input('page_index_box_menu_border_radius'), true);
        Settings::set('page_refresh_fixed_button', $request->input('page_refresh_fixed_button'), true);
        Settings::set('page_publish_fixed_button', $request->input('page_publish_fixed_button'), true);
        Settings::set('waterfall_img_max_height', $request->input('waterfall_img_max_height'), true);
        Settings::set('waterfall_random_bg_font_size', $request->input('waterfall_random_bg_font_size'), true);
        Settings::set('waterfall_random_bg_padding', $request->input('waterfall_random_bg_padding'), true);
        Settings::set('waterfall_random_bg_max_height', $request->input('waterfall_random_bg_max_height'), true);
        Settings::set('waterfall_random_bg_justify_content', $request->input('waterfall_random_bg_justify_content'), true);

        Settings::set('post_list_sex_display', $request->input('post_list_sex_display'), true);
        Settings::set('ellipsis_content_height', $request->input('ellipsis_content_height'), true);
        Settings::set('comment_list_sex_display', $request->input('comment_list_sex_display'), true);
        Settings::set('comment_form_placeholder_text', $request->input('comment_form_placeholder_text'), true);
        Settings::set('sticky_clrcle_display', $request->input('sticky_clrcle_display'), true);

        Settings::set('post_list_footer_share_icon', $request->input('post_list_footer_share_icon'), true);
        Settings::set('post_list_footer_icon_font_size', $request->input('post_list_footer_icon_font_size'), true);

        Settings::set('uni_tabbar_style', $request->input('uni_tabbar_style'), true);
        Settings::set('uni_tabbar_style_publish_img', $request->input('uni_tabbar_style_publish_img'), true);

        Settings::set('uni_tabbar_style_1_text', $request->input('uni_tabbar_style_1_text'), true);
        Settings::set('uni_tabbar_style_2_text', $request->input('uni_tabbar_style_2_text'), true);
        Settings::set('uni_tabbar_style_3_text', $request->input('uni_tabbar_style_3_text'), true);
        Settings::set('uni_tabbar_style_4_text', $request->input('uni_tabbar_style_4_text'), true);
        Settings::set('uni_tabbar_style_5_text', $request->input('uni_tabbar_style_5_text'), true);

        Settings::set('uni_tabbar_style_1_icon_1', $request->input('uni_tabbar_style_1_icon_1'), true);
        Settings::set('uni_tabbar_style_2_icon_1', $request->input('uni_tabbar_style_2_icon_1'), true);
        Settings::set('uni_tabbar_style_3_icon_1', $request->input('uni_tabbar_style_3_icon_1'), true);
        Settings::set('uni_tabbar_style_4_icon_1', $request->input('uni_tabbar_style_4_icon_1'), true);
        Settings::set('uni_tabbar_style_5_icon_1', $request->input('uni_tabbar_style_5_icon_1'), true);

        Settings::set('uni_tabbar_style_1_icon_2', $request->input('uni_tabbar_style_1_icon_2'), true);
        Settings::set('uni_tabbar_style_2_icon_2', $request->input('uni_tabbar_style_2_icon_2'), true);
        Settings::set('uni_tabbar_style_3_icon_2', $request->input('uni_tabbar_style_3_icon_2'), true);
        Settings::set('uni_tabbar_style_4_icon_2', $request->input('uni_tabbar_style_4_icon_2'), true);
        Settings::set('uni_tabbar_style_5_icon_2', $request->input('uni_tabbar_style_5_icon_2'), true);

        Settings::set('desai_pc_page_welcome', $request->input('desai_pc_page_welcome'), true);
        Settings::set('desai_pc_page_title', $request->input('desai_pc_page_title'), true);
        Settings::set('desai_pc_page_keyword', $request->input('desai_pc_page_keyword'), true);
        Settings::set('desai_pc_page_desc', $request->input('desai_pc_page_desc'), true);
        Settings::set('desai_pc_logo', $request->input('desai_pc_logo'), true);
        Settings::set('desai_pc_icon', $request->input('desai_pc_icon'), true);
        Settings::set('desai_pc_right_bottom_qrcode', $request->input('desai_pc_right_bottom_qrcode'), true);
        Settings::set('desai_pc_app_order_pay_provider', $request->input('desai_pc_app_order_pay_provider'), true);
        Settings::set('desai_pc_app_order_pay_type', $request->input('desai_pc_app_order_pay_type'), true);

        Settings::set('uni_front_replace_list', AdminUtils::key_value_process($request->input('uni_front_replace_list')), true);

        Settings::set('mini_plugin_ant_movie_switch', $request->input('mini_plugin_ant_movie_switch'), true);
        Settings::set('mini_plugin_ant_movie_apikey', $request->input('mini_plugin_ant_movie_apikey'), true);

        return $this->response()->success('成功！');
    }

}
